// pages/mine/myform/deliverGoods/deliverGoods.js
const app = getApp();
const util = require("../../../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderId: "",
    order: []
  },

  // 取消订单
  cancelOrder: function (e) {
    let that = this
    // console.log(e.currentTarget.id)
    wx.showModal({
      title: '取消订单',
      content: '您确认取消该订单吗',
      confirmText: "确认",
      cancelText: "取消",
      success: res => {
        if (res.confirm) {
          // 发送取消订单请求
          let cancleOrderUrl = app.globalData.baseUrl + "weixin/cancleOrder"
          let data = {
            orderId: that.data.orderId
          }
          util.requestLoading(cancleOrderUrl, data, "GET").then(res => {
            // console.log(res)
            wx.showModal({
              content: '订单已取消，款项将在三个工作日内返还，如未返还，请联系客服',
              showCancel: false,
              success: res => {
                if (res.confirm) {
                  wx.reLaunch({
                    url: '../myform',
                  })
                }
              }
            })
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log(options.orderId)
    let that = this
    that.setData({
      orderId: options.orderId
    })
    // 请求页面数据
    let waitSendOrdersDetailUrl = app.globalData.baseUrl + "weixin/waitSendOrdersDetail"
    let data = {
      orderId: that.data.orderId
    }
    util.requestLoading(waitSendOrdersDetailUrl, data, "GET").then(res => {
      // console.log(res)
      that.setData({
        order: res.data.order
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})